
Public Class B1FormAddonVariables
    Private _FormType As String
    Private _UserVariables As New Hashtable

    Sub New(ByVal FormType As String)
        _FormType = FormType

    End Sub

    Public ReadOnly Property FormType() As String
        Get
            Return _FormType
        End Get
    End Property

    Public ReadOnly Property Count() As Integer
        Get
            Return Me._UserVariables.Count
        End Get
    End Property

    Public Function Item(ByVal FormUID As String) As B1FormVariables
        If Me._UserVariables.ContainsKey(FormUID) Then
            Return _UserVariables.Item(FormUID)
        Else
            Return Nothing
        End If
    End Function

    Public Sub Add(ByVal formVar As B1FormVariables)
        If _UserVariables.ContainsKey(formVar.FormUID) Then
            _UserVariables.Remove(formVar.FormUID)
            _UserVariables.Add(formVar.FormUID, formVar)
        Else
            _UserVariables.Add(formVar.FormUID, formVar)
        End If
    End Sub


    Public Sub Remove(ByVal formUID As String)
        If _UserVariables.ContainsKey(formUID) Then
            _UserVariables.Item(formUID) = Nothing
            _UserVariables.Remove(formUID)
        End If
    End Sub
End Class


Public Class B1FormVariables
    Private _FormUID As String
    Private _variables As New Hashtable

    Sub New(ByVal formUID As String)
        _FormUID = formUID
    End Sub

    Public ReadOnly Property FormUID() As String
        Get
            Return _FormUID
        End Get
    End Property

    Public ReadOnly Property Count() As Integer
        Get
            Return Me._variables.Count
        End Get
    End Property

    Public Function Item(ByVal Key As Object) As B1FormVariable
        If Me._variables.ContainsKey(Key) Then
            Return _variables.Item(Key)
        Else
            Return Nothing
        End If
    End Function

    Public Sub Add(ByVal Obj As B1FormVariable)
        If Me._variables.ContainsKey(Obj.Name) Then
            Me._variables.Remove(Obj.Name)
            Me._variables.Add(Obj.Name, Obj)
        Else
            Me._variables.Add(Obj.Name, Obj)
        End If
    End Sub

    Public Function Add(ByVal ObjName As String) As B1FormVariable
        If Me._variables.ContainsKey(ObjName) Then
            Throw New Exception(ObjName & " is already existed.")
        Else
            Dim obj As New B1FormVariable(ObjName)
            Me._variables.Add(obj.Name, obj)
            Return obj
        End If
    End Function

    Public Sub Remove(ByVal Name As String)
        If Me._variables.ContainsKey(Name) Then
            Me._variables.Remove(Name)
        End If
    End Sub

End Class


Public Class B1FormVariable
    Private _Name As String
    Private _Obj As Object

    Sub New(ByVal Name As String)
        _Name = Name
    End Sub

    Public ReadOnly Property Name() As String
        Get
            Return _Name
        End Get
    End Property

    Public Property Value() As Object
        Get
            Return _Obj
        End Get
        Set(ByVal value As Object)
            _Obj = value
        End Set
    End Property

End Class
